﻿using UnityEngine;
using UnityEditor;

namespace CWM.Skinn
{
    public static partial class SkinnContextCommands
    {
        [CtxMenuItem("SkinnedMeshRenderer/Bones/Optimize Array",
            "Remove any unused bones from a mesh's bind-poses and reorganizes bone-weights.", 0)]
        public static void SkinnedMeshRendererOptimizeBoneArray()
        {
            foreach (var item in SkinnContext.GetContextItems())
            {
                var context = item.GetComponent<SkinnedMeshRenderer>();
                if (SkinnEx.IsNullOrNotInAScene(context)) continue;
                Undo.RecordObject(context, "Optimize Bones");
                SkinnContext.OptimizeMesh(context, false);
            }
            SkinnContext.Finished();
        }
    }
}